package com.tandashi.springbootstudy01.sensor.receiver;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public abstract class ActivityReceiver<T extends ActivityRecord> extends JsonReceiver<T> {

    protected abstract void receiveAction(T message) throws Exception;

    @Override
    protected void doReceive(T message) throws Exception {
        logMessage(message);
        receiveAction(message);
    }

    @Override
    public String tag() {
        return null;
    }

    private void logMessage(Object obj) {
        try {
            log.warn("act_received_message_{} {}", topic(), objectMapper.writeValueAsString(obj));
        } catch (Exception ignore) {
        }
    }
}
